package com.nahan.secondapplication

import android.content.Intent
import android.content.res.Configuration
import android.graphics.BitmapFactory
import android.os.Bundle
import android.os.Handler
import android.util.Log
import com.google.vr.sdk.widgets.pano.VrPanoramaEventListener
import com.google.vr.sdk.widgets.pano.VrPanoramaView
import com.nahan.secondapplication.AppUpdate.AppUpdateActivity
import com.nahan.secondapplication.BesselMovement.BesselMovementActivity
import com.nahan.secondapplication.CityList.CityPickerActivity
import com.nahan.secondapplication.ClassScheduleCard.ClassScheduleCardActivity
import com.nahan.secondapplication.CommentReply.CommentReplyActivity
import com.nahan.secondapplication.CustomProgressBar.CustomProgressBarActivity
import com.nahan.secondapplication.Custombulletframe.CustomPopwindowsActivity
import com.nahan.secondapplication.GLS_OpenBook.FlipActivity
import com.nahan.secondapplication.ImitateDouYin.FangDouYinActivity
import com.nahan.secondapplication.Jiugongge.JiugonggeActivity
import com.nahan.secondapplication.LottieAnimation.LottieActivity
import com.nahan.secondapplication.Mesh.MeshActivity
import com.nahan.secondapplication.OpenBook.ReadActivity
import com.nahan.secondapplication.PersistenceVerificationCode.PersistenceVerificationCodeActivity
import com.nahan.secondapplication.QuestionAnswerTab.ExpansionPanelMainActivity
import com.nahan.secondapplication.Screen.ScreenActivity
import com.nahan.secondapplication.SlidingDrawer.SlidingDrawerActivity
import com.nahan.secondapplication.SlidingPanelLayout.PanelActivity
import com.nahan.secondapplication.StackedBarChart.StackedBarActivity
import com.nahan.secondapplication.StackedCustom.StackedCustomActivity
import com.nahan.secondapplication.SwitvhButtonAll.SwitchActivity
import com.nahan.secondapplication.Ticketing.OutTicketActivity
import com.nahan.secondapplication.VectorIllustration.VectorIllustrationActivity
import com.nahan.secondapplication.VerticalViewPagerRelated.VerticalViewPager
import com.nahan.secondapplication.VerticalViewPagerRelated.VerticalViewPagerActivity
import com.nahan.secondapplication.base.BaseActivity
import com.nahan.secondapplication.base.BasePresenter
import com.nahan.secondapplication.base.LoadingLayout
import com.nahan.secondapplication.coorAndappbar.AppBarLayoutActivity
import com.nahan.secondapplication.evaluation.EvaluationActivity
import com.nahan.secondapplication.goodsdetail.GoodsActivity
import com.nahan.secondapplication.navigation.NavigationActivity
import com.nahan.secondapplication.smoothcheckbox.SmoothCheckBoxActivity
import kotlinx.android.synthetic.main.activity_vr.*
import java.io.IOException
import java.io.InputStream

class VrActivity : BaseActivity<BasePresenter>() {

    val tag = "cccc"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ShowLoading()

    }
    override fun setContentView(): Int {
        return R.layout.activity_vr
    }

    override fun init() {
        Log.e("life_cycle","onCreate")
        onClick()
        load360Image()

        initview()

        Handler().postDelayed(Runnable {
            //加载成功
            ShowLoadSuccess(LoadingLayout.LOAD_SUCCESS_STATE)
            //加载失败
//            ShowLoadFailureMessage { v: View? ->
//                    ShowLoading()
//            }
            //没有网络
//            ShowNetErrorMessage{v ->
//                ShowLoading()
//            }
            //没有数据
//            ShowNullDataMessage()
        },2000)
    }

    private fun initview() {
        round_flikerbar.progress=50f
    }

    override fun onStart() {
        super.onStart()
        Log.e("life_cycle","onStart")
    }

    override fun onResume() {
        super.onResume()
        Log.e("life_cycle","onResume")
    }

    override fun onPause() {
        super.onPause()
        Log.e("life_cycle","onPause")
    }

    override fun onStop() {
        super.onStop()
        Log.e("life_cycle","onStop")
    }

    override fun onRestart() {
        super.onRestart()
        Log.e("life_cycle","onRestart")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.e("life_cycle","onDestroy")
    }

    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        Log.e("life_cycle","onConfigurationChanged")
    }

    /**
     * 监听事件
     */
    private fun onClick() {

        //仿淘宝商品详情
        taobao.setOnClickListener {
            startActivity(Intent(this,GoodsActivity::class.java))
        }

        //自定义内容
        custom.setOnClickListener {
            startActivity(Intent(this,CustomActivity::class.java))
        }

        //CoordinatorLayout+AppBarLayout实现拉伸头部图片
        cl_abl.setOnClickListener {
            startActivity(
                Intent(this,
                    AppBarLayoutActivity::class.java))
        }

        //导航布局，带横向滚动条
        Transformers.setOnClickListener {
            startActivity(Intent(this,NavigationActivity::class.java))
        }

        //评论回复功能
        Comment_reply.setOnClickListener {
            startActivity(Intent(this,CommentReplyActivity::class.java))
        }

        //课程表
        Class_Schedule_Card.setOnClickListener {
            startActivity(Intent(this,ClassScheduleCardActivity::class.java))
        }

        //滑动抽屉效果
        Sliding_drawer.setOnClickListener {
            startActivity(Intent(this,SlidingDrawerActivity::class.java))
        }

        //贝塞尔属性运动
        Bessel_movement.setOnClickListener {
            startActivity(Intent(this, BesselMovementActivity::class.java))
        }

        //网状图
        Mesh.setOnClickListener {
            startActivity(Intent(this, MeshActivity::class.java))
        }

        //持久化验证码
        PersistenceVerificationCode.setOnClickListener {
            startActivity(Intent(this, PersistenceVerificationCodeActivity::class.java))
        }

        //筛选
        screen.setOnClickListener {
            startActivity(Intent(this, ScreenActivity::class.java))
        }

        //翻书
        Open_Book.setOnClickListener {
            startActivity(Intent(this, ReadActivity::class.java))
        }

        //GLSurfaceView实现翻书
        GLS_Open_Book.setOnClickListener {
            startActivity(Intent(this, FlipActivity::class.java))
        }

        //堆叠条形图
        duidie.setOnClickListener {
            startActivity(Intent(this, StackedBarActivity::class.java))
        }

        //自定义堆叠条形图
        custom_duidie.setOnClickListener {
            startActivity(Intent(this, StackedCustomActivity::class.java))
        }

        //仿美团的导航栏的lottie动画
        Lottie_animation.setOnClickListener {
            startActivity(Intent(this, LottieActivity::class.java))
        }

        //可以在竖直方向上操控多个panel
        panel.setOnClickListener {
            startActivity(Intent(this, PanelActivity::class.java))
        }

        //如解答问题的选项卡
        tab.setOnClickListener {
            startActivity(Intent(this, ExpansionPanelMainActivity::class.java))
        }

        //带动画的check
        check.setOnClickListener {
            startActivity(Intent(this, SmoothCheckBoxActivity::class.java))
        }

        //九宫格显示图片
        Jiugongge.setOnClickListener {
            startActivity(Intent(this, JiugonggeActivity::class.java))
        }

        //App更新
        appupdate.setOnClickListener {
            startActivity(Intent(this, AppUpdateActivity::class.java))
        }

        //星星评价
        Evaluation.setOnClickListener {
            startActivity(Intent(this, EvaluationActivity::class.java))
        }
        //仿京东的城市选择
        City_list.setOnClickListener {
            startActivity(Intent(this, CityPickerActivity::class.java))
        }

        //矢量图学习
        Vector_illustration.setOnClickListener {
            startActivity(Intent(this, VectorIllustrationActivity::class.java))
        }

        //仿抖音评论
        Imitate.setOnClickListener {
            startActivity(Intent(this, FangDouYinActivity::class.java))
        }

        //仿订单出票效果
        Ticketing.setOnClickListener {
            startActivity(Intent(this, OutTicketActivity::class.java))
        }

        //自定义弹框
        custom_tan.setOnClickListener {
            startActivity(Intent(this, CustomPopwindowsActivity::class.java))
        }

        //自定义ProgressBar
        custom_ProgressBar.setOnClickListener {
            startActivity(Intent(this, CustomProgressBarActivity::class.java))
        }

        //垂直viewpager
        vertical_viewpager.setOnClickListener {
            startActivity(Intent(this, VerticalViewPagerActivity::class.java))
        }
        //开关按钮
        Switch_button.setOnClickListener {
            startActivity(Intent(this, SwitchActivity::class.java))
        }

    }

    /**
     * 加载360度全景图片
     */
    private fun load360Image() {
        /**获取assets文件夹下的图片 */
        var open: InputStream? = null
        try {
            open = assets.open("andes.jpg")
        } catch (e: IOException) {
            e.printStackTrace()
        }
        val bitmap = BitmapFactory.decodeStream(open)

        /**设置加载VR图片的相关设置 */
        val options = VrPanoramaView.Options()
        options.inputType = VrPanoramaView.Options.TYPE_STEREO_OVER_UNDER
        //  mVrPanoramaView.setFullscreenButtonEnabled (false); //隐藏全屏模式按钮
        vr_pan_view.setInfoButtonEnabled(false); //设置隐藏最左边信息的按钮
        vr_pan_view.setStereoModeButtonEnabled(false); //设置隐藏立体模型的按钮
        /**设置加载VR图片监听 */
        vr_pan_view.setEventListener(object : VrPanoramaEventListener() {
            /**
             * 显示模式改变回调
             * 1.默认
             * 2.全屏模式
             * 3.VR观看模式，即横屏分屏模式
             * @param newDisplayMode 模式
             */
            override fun onDisplayModeChanged(newDisplayMode: Int) {
                super.onDisplayModeChanged(newDisplayMode)
                Log.d(
                    tag,
                    "onDisplayModeChanged()->newDisplayMode=$newDisplayMode"
                )
            }

            /**
             * 加载VR图片失败回调
             * @param errorMessage
             */
            override fun onLoadError(errorMessage: String) {
                super.onLoadError(errorMessage)

                Log.d(tag, "onLoadError()->errorMessage=$errorMessage")
            }

            /**
             * 加载VR图片成功回调
             */
            override fun onLoadSuccess() {
                super.onLoadSuccess()
                Log.d(tag, "onLoadSuccess->图片加载成功")
            }

            /**
             * 点击VR图片回调
             */
            override fun onClick() {
                super.onClick()
                Log.d(tag, "onClick()")
            }
        })
        /**加载VR图片 */
        vr_pan_view.loadImageFromBitmap(bitmap, options)
    }




}
